package com.tansun.easycare.rule.rulegroup.model;

import java.util.ArrayList;
import java.util.List;

import com.tansun.rule.utils.StringUtils;

/**
 * 规则条目权重条件
 * @author xuconghui
 *
 */
public class RuleEntryCondition {
	
	public String optSym;
	public String symbol;
	public String symbolVal;
	
	public RuleEntryCondition(String optSym, String symbol, String symbolVal) {
		super();
		this.optSym = optSym;
		this.symbol = symbol;
		this.symbolVal = symbolVal;
	}
	
	public static List<RuleEntryCondition> newInstance(String condition,boolean changeCode){
		List<RuleEntryCondition> list = new ArrayList<RuleEntryCondition>();
		if(StringUtils.isNotEmpty(condition)) {
			String[] arr = condition.split("###");
			for(int i=0;i<arr.length;i++) {
				String[] arrchild = arr[i].split("---");
				if(changeCode) {
					arrchild[1] = arrchild[1].replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll("\"","&quot;").replaceAll(" ","&nbsp;");
				}
				String temp = "0";
				if(arrchild.length==3) {
					temp = arrchild[2];
				}
				list.add(new RuleEntryCondition(arrchild[0],arrchild[1],temp));
			}
		}
		return list;
	}
	public static String getCoditionStr(List<RuleEntryCondition> conditions){
		return StringUtils.join(conditions,"###");
	}
	
	public String getOptSym() {
		return optSym;
	}
	public void setOptSym(String optSym) {
		this.optSym = optSym;
	}
	public String getSymbol() {
		return symbol;
	}
	public void setSymbol(String symbol) {
		this.symbol = symbol;
	}
	public String getSymbolVal() {
		return symbolVal;
	}
	public void setSymbolVal(String symbolVal) {
		this.symbolVal = symbolVal;
	}

	@Override
	public String toString() {
		return  (optSym==null?"":optSym) + "---" + symbol + "---" + symbolVal;
	}

}
